<template>
    <div>
        <h2>查看用户资料</h2>
        <el-form>
            <el-form-item label="用户名">
                {{user.username}}
            </el-form-item>
            <el-form-item label="邮箱" v-if="$store.state.user.level.id <=4">
                {{user.email}}
            </el-form-item>
            <el-form-item label="手机号码" v-if="$store.state.user.level.id <=4">
                {{user.phone}}
            </el-form-item>
            <el-form-item label="最后登录时间">
                {{user.last_sign_in_at}}
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                user: {},
            }
        },
        methods: {
            fetch() {
                const {id} = this.$route.params;
                this.$http.get('/api/user/' + id).then(res => {
                    this.user = res.data;
                    this.user.last_sign_in_at = moment(this.user.last_sign_in_at).calendar();
                }).catch(() => {
                    this.$router.replace('/404');
                });
            }
        }
    }
</script>

<style scoped>

</style>